package com.apes.framework.plugin.soe.metadata;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Set;

/**
 * 功能：凭证类型
 *
 * @author xul
 * @create 2018-09-21 14:05
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = BusinessType.CONST_TABLE_NAME)
public class BusinessType extends BaseModel {
    public static final String CONST_TABLE_NAME = "soe_business_type";

    @Id
    @Column(name = "id", length = 64)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "凭证类型")
    @Comment("编码")
    private String id;

    @Column(name = "name", nullable = false, length = 120)
    @Comment("名称")
    private String name;

    @Column(name = "valid", columnDefinition = "number(1,0) default 1")
    @Comment("是否有效")
    private boolean valid = true;

    @Column(name = "is_aggregate_root", columnDefinition = "number(1,0) default 1")
    @Comment("是否聚合根")
    private boolean aggregateRoot;

    @JSONField(serialize = false)
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "businessType")
    private Set<SceneRole> sceneRoles; // 场景类型

    @Column(name = "form_id", length = 120)
    @Comment("表单编号")
    private String formId;

}
